<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class DischargeScoreLogsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        foreach (range(0, 9) as $item) {
            Schema::create('score_logs_' . $item, function (Blueprint $table) {
                $table->increments('id');
                $table->string('room_id')->comment('房间 ID');
                $table->unsignedInteger('user_id')->default('0')->comment('用户 ID');
                $table->unsignedInteger('pk_user_id')->default('0')->comment('对手用户 ID');
                $table->unsignedTinyInteger('is_robot')->default('0')->comment('是否机器人');
                $table->unsignedTinyInteger('is_win')->comment('是否胜利 0 失败 1 胜利 2 平局');
                $table->unsignedInteger('score')->default('0')->comment('得分');
                $table->timestamp('created_at')->nullable();

                $table->unique(['room_id', 'user_id']);
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        foreach (range(0, 9) as $item) {
            Schema::dropIfExists('score_logs_' . $item);
        }
    }
}
